//
//  ProtocolExt.swift
//  ProtocolKitSDK
//
//  Created by admin on 2022/3/17.
//
import UIKit
import Foundation

extension tapActionprotocol where Self:UIView{
    public var value : TimeInterval{
        return 1
    }
    
    public var toValue : TimeInterval{
        return 0.9
    }
    
    public var duration : TimeInterval{
        return 0.2
    }
    
    public var delayScaleofduration : TimeInterval{
        return 0.1
    }
    
    public var autorever : Bool{
        return true
    }
    
    public func tapAction(finsh:@escaping()->Void){
        tapActions(duration: duration)
        DispatchQueue.main.asyncAfter(deadline:DispatchTime.now() + duration*delayScaleofduration) {
            finsh()
        }
    }
    
    public func tapActionwithDuration(duration:TimeInterval,delayScaleofduration:Double?=0.05,finsh:@escaping()->Void){
        tapActions(duration: duration)
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + duration*delayScaleofduration!) {
            finsh()
        }
    }
    private func tapActions(duration:TimeInterval){
        let animation = CABasicAnimation.init(keyPath: "transform.scale")
        animation.fromValue = value
        animation.toValue = toValue
        animation.autoreverses = autorever
        animation.duration = duration  
        self.layer.add(animation, forKey:"cell-scale")
    }
}



extension touchDelegate{
    func touchEnd(){

    }
}

